package com.tracesystem.security.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tracesystem.controller.info.UserInfo;
import com.tracesystem.model.IssueUser;
import com.tracesystem.service.IssueUserService;
import com.tracesystem.util.WoniuCopyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {
	
	@Autowired
	private IssueUserService issueUserService;

	@Override
	public UserDetails loadUserByUsername(String username){

        IssueUser user = issueUserService.getOne(new QueryWrapper<IssueUser>().eq("USERNAME", username));
		if(user == null) throw new UsernameNotFoundException("账号不存在");
		return WoniuCopyUtil.copyOne(user, UserInfo.class);
	}
	
}